package com.zzl.study.auth.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: zhangzl
 * @date: 2023/12/8 10:49
 * @version: 1.0
 * @description: 响应结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> {

    /**
     * 响应码
     */
    private int code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应结果
     */
    private T result;

    public static <T> Response<T> success(T result) {
        return new Response<T>(0, null, result);
    }

    public static Response error(int code) {
        return error(code, "未知异常");
    }

    public static Response error(int code, String msg) {
        return error(code, msg, null);
    }

    public static Response error(int code, String msg, Object result) {
        return new Response<Object>(code, msg, result);
    }

}
